//
//  RankListDetailTableViewCell.m
//  LuckyRadio
//
//  Created by Mr、J on 15/11/23.
//  Copyright © 2015年 chenjun. All rights reserved.
//

#import "RankListDetailTableViewCell.h"

#define SCREEN_WIDTH [UIScreen mainScreen].bounds.size.width

#define SCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height

#define WIDTH_PRO(X) (X)*(SCREEN_WIDTH/375)

#define HEIGHT_PRO(Y) (Y)*(SCREEN_HEIGHT/667)
@implementation RankListDetailTableViewCell
- (void)dealloc
{
    [_songsModel release];
    [_titleLabel release];
    [_numLabel release];
    [_nameLabel release];
    [_tagImage release];
    [_listenCountLabel release];
    [super dealloc];
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if ([super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        [self createSubViews];
    }
    return self;
}

-(void)createSubViews
{
    self.numLabel = [[UILabel alloc] init];
    self.numLabel.textColor = [UIColor grayColor];
    self.numLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.numLabel];
    [_numLabel release];
    
    self.titleLabel = [[UILabel alloc] init];
    self.titleLabel.font = [UIFont systemFontOfSize:15];
    [self.contentView addSubview:self.titleLabel];
    [_titleLabel release];
    
    self.nameLabel = [[UILabel alloc] init];
    self.nameLabel.textColor = [UIColor grayColor];
    self.nameLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.nameLabel];
    [_nameLabel release];
    
    self.tagImage = [[UIImageView alloc] init];
    [self.contentView addSubview:self.tagImage];
    [_tagImage release];
    
    self.listenCountLabel = [[UILabel alloc] init];
    self.listenCountLabel.textColor = [UIColor grayColor];
    self.listenCountLabel.font = [UIFont systemFontOfSize:12];
    [self.contentView addSubview:self.listenCountLabel];
    [_listenCountLabel release];
    
}

-(void)layoutSubviews
{
    [super layoutSubviews];
    self.numLabel.frame = CGRectMake(WIDTH_PRO(20), HEIGHT_PRO(20), WIDTH_PRO(50), HEIGHT_PRO(20));
    self.titleLabel.frame = CGRectMake(self.numLabel.frame.origin.x + self.numLabel.frame.size.width + WIDTH_PRO(10), HEIGHT_PRO(10), SCREEN_WIDTH - self.numLabel.frame.size.width - self.titleLabel.frame.size.width + WIDTH_PRO(40), HEIGHT_PRO(20));

    
    CGRect tmpRect = [self.nameLabel.text boundingRectWithSize:CGSizeMake(320, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObjectsAndKeys:self.nameLabel.font,NSFontAttributeName, nil] context:nil];
    self.nameLabel.frame = CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.origin.y + self.titleLabel.frame.size.height + HEIGHT_PRO(5), tmpRect.size.width, HEIGHT_PRO(20));
    
    self.tagImage.frame = CGRectMake(self.nameLabel.frame.origin.x + self.nameLabel.frame.size.width + WIDTH_PRO(10), self.nameLabel.frame.origin.y , WIDTH_PRO(20), HEIGHT_PRO(20));
    self.listenCountLabel.frame = CGRectMake(self.tagImage.frame.origin.x + self.tagImage.frame.size.width + WIDTH_PRO(10), self.nameLabel.frame.origin.y, WIDTH_PRO(100), HEIGHT_PRO(20));
    
    
}

-(void)setSongsModel:(SongsModel *)songsModel
{
    if (_songsModel != songsModel) {
        [_songsModel release];
        _songsModel = [songsModel retain];
    }
    
    self.titleLabel.text = songsModel.name;
    self.nameLabel.text = songsModel.singerName;
    self.tagImage.image = [UIImage imageNamed:@"list_menu_favorite"];
    self.listenCountLabel.text = [NSString stringWithFormat:@"%@", songsModel.favorites];
    if ([songsModel.favorites floatValue] > 10000) {
        
        CGFloat tmp = [songsModel.favorites floatValue] / 10000;
        self.listenCountLabel.text = [NSString stringWithFormat:@"%.1f万", tmp];
    }
    
}

+(RankListDetailTableViewCell *)rankListDetailTableViewCellWith:(UITableView *)tableView
{
    static NSString *cellIdentify = @"cellIdentify";
    RankListDetailTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentify];
    if (!cell) {
        cell = [[RankListDetailTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentify];
    }
    return cell;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
